package org.javaweb.cms_web.service;

import org.javaweb.cms_web.mapper.PermissionMapper;
import org.javaweb.cms_web.model.UserPermission;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PermissionService {
    @Resource
    private PermissionMapper permissionMapper;

    public void setPermissionsForUser(int userId, List<Integer> permissionTypes) {
        permissionMapper.deletePermissionsByUserId(userId);
        for (int permissionType : permissionTypes) {
            permissionMapper.addPermissionForUser(userId, permissionType);
        }
    }

    public List<UserPermission> getPermissionsByUserId(int userId) {
        return permissionMapper.getPermissionsByUserId(userId);
    }

}
